package indi.kider.server.appclient.api;

import indi.kider.common.model.apartment.DevLock;
import indi.kider.server.appclient.service.related.LockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.vankid.common.model.base.CommonResponse;

@RestController
@RequestMapping(value = "lock", produces = "application/json;charset=UTF-8")
public class AppClientLockController {
    @Autowired
    private LockService lockService;

    /**
     * @api {GET} house/{houseId}
     * @apiGroup app-client
     * @apiDescription 根据房间ID查询锁信息
     * @apiParamExample 请求样例：
     * http://localhost:9002/app-client/lock/house/1
     * @apiSuccessExample {json} 返回样例:
     * {
     * "status": "200",
     * "msg": "查询成功！",
     * "data":
     * {
     * "id": 1, --id
     * "houseId": 1,--房间id
     * "partnerCode": 'xx', -- 来源id(合作商id)
     * "name": 'xx',-- 姓名
     * "code": 'xx',-- 未说明
     * "imei":  'xx',-- imei
     * "cert":  'xx',-- 未说明
     * "regCode": 'xx',-- 未说明
     * "state": 2, -- 1:未安装;2:已绑定用户 99失效
     * "createDate": 'xx',-- 时间
     * "created": 1,--添加人ID
     * "createName": 'xx',--添加人姓名
     * }
     * }
     **/
    @GetMapping("/house/{houseId}")
    public CommonResponse lockByHouseId(@PathVariable Long houseId) {
        return lockService.lockByHouseId(houseId);
    }

    /**
     * @api {PUT} /
     * @apiGroup app-client
     * @apiDescription 修改锁信息
     * @apiParamExample 请求样例：
     * http://localhost:9002/app-client/lock
     * {id:"1","name":'锁具名称',"houseId":房间id}
     * @apiSuccessExample {json} 返回样例:
     * {status": "202","msg": "保存成功！","data": "" }
     */
    @PutMapping("")
    public CommonResponse updateDevLock(@RequestBody DevLock devLock) {
        return lockService.updateDevLock(devLock);
    }

}
